# #Lagos download script
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
iowa <- states %>%
filter(name == "Iowa") %>%
st_transform(2163)
illinois <- states %>%
filter(name == "Illinois") %>%
st_transform(2163)
iail <- rbind(iowa,illinois)
mapview(iail)
Minnesota has ~29,000 lakes while Illinois and Iowa combined only have ~16,500 lakes. This is understandable as Minnesota is known as the land of many lakes.
iail_lakes <- spatial_lakes[iail,]
#combining Iowa and Minnesota
iamn <- rbind(iowa,minnesota)
#subsetting lakes
iamn_lakes <- spatial_lakes %>%
.[iamn,] %>%
st_join(iamn)
ggplot()+
geom_histogram(filter(iamn_lakes, name == 'Iowa'), mapping = aes(lake_area_ha), bins = 20, color = "red", fill = "orange")+
scale_x_log10()+
labs(x = 'Lake Area (ha)', y = 'Frequency') +
geom_histogram(filter(iamn_lakes, name == "Minnesota"), mapping = aes(lake_area_ha),bins = 20, color = "blue", fill = "light green")+
scale_x_log10()+
labs(x = 'Lake Area (ha)', y = 'Frequency', title = 'Iowa vs Minnesota Lakes Size Distribution')+
facet_wrap(~name)
Figure 1. The distribution of lake sizes in Iowa vs. Minnesota. Both states share a similar distribution of lakes, with the majority being smaller than 1 ha. However, based on the histograms, it is demonstrated how many more lakes Minnesota contains based on the frequencies of the lake sizes. Histogram code used from: http://www.sthda.com/english/wiki/ggplot2-histogram-plot-quick-start-guide-r-software-and-data-visualization and WR418 assignment, Accessed: 2/23/2022
iail_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
Other data sources we could use to understand reservoirs and natural lakes vary in size would be remote sensing imagery. Landsat has been used in several studies looking at lake sizes, as well as how they are changing over time. With this continuous data source, great insight could be provided to visualize the variation of water bodies in these 3 states.